package com.customComponents;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bfb.R;

public class ImageText extends LinearLayout {

	TextView textView;
	ImageView imageView;

	public ImageText(Context context, AttributeSet attr) {
		super(context, attr);
		initializeLayoutBasics(context);
		imageView = (ImageView) findViewById(R.id.imageCustom);
		textView = (TextView) findViewById(R.id.imageCustomText);
		textView.setGravity(Gravity.CENTER);
	}

	private void initializeLayoutBasics(Context context) {
		setOrientation(VERTICAL);
		final LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.image_text_customview, this);
	}

	public void setText(String text) {
		textView.setText(text);
	}

	public void setDrawable(Drawable d) {
		imageView.setImageDrawable(d);
	}

	public void setResource(int id) {
		imageView.setImageResource(id);
	}

	public void setBitmap(Bitmap bitmap, int width, int height, boolean scale) {
		if (scale)
			imageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, width,
					height, true));
		else
			imageView.setImageBitmap(bitmap);
	}

	public TextView getTextView() {
		return textView;
	}

	public ImageView getImageView() {
		return imageView;
	}
}

// http://www.workreloaded.com/2011/02/composite-component/
